package com.springboot.service.imp;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springboot.common.MyMsg;
import com.springboot.dao.TMemberMapper;
import com.springboot.entity.TMember;
import com.springboot.entity.TMemberExample;
import com.springboot.entity.TMemberExample.Criteria;
import com.springboot.service.TMemberService;

@Service
public class TMemberServiceImp implements TMemberService {
	@Autowired
	TMemberMapper memberMapper;

	Logger logger = LoggerFactory.getLogger(TMemberServiceImp.class);

	@Override
	public List<TMember> getMembers() {
		return memberMapper.selectByExample(null);
	}

	@Override
	public MyMsg<TMember> memberOpe(String memId, String statuscode) {
		TMemberExample example = new TMemberExample();
		Criteria criteria = example.createCriteria();
		criteria.andMIdEqualTo(Integer.parseInt(memId));
		List<TMember> list = memberMapper.selectByExample(example);
		if (list != null && list.size() == 1) {
			TMember member = list.get(0);
			// 0 正常 1 禁止登录
			if (member.getmStatus().equals("0")) {
				member.setmStatus("1");
			} else {
				member.setmStatus("0");
			}
			int affectNum = memberMapper.updateByExample(member, example);
			if (affectNum == 1) {
				return MyMsg.success("已执行", member, null);
			}
		}
		return MyMsg.success("操作失败，请重试", null, null);
	}
}
